package com.micro.ai.commons.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.io.Serializable;

/**
 * 分页查询基类
 * 
 * @author micro-ai
 * @since 0.0.1
 */
@Data
public class PageQuery implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 当前页码
     */
    @Min(value = 1, message = "页码不能小于1")
    private Long current = 1L;

    /**
     * 页大小
     */
    @Min(value = 1, message = "页大小不能小于1")
    @Max(value = 1000, message = "页大小不能超过1000")
    private Long size = 10L;

    /**
     * 排序字段
     */
    private String orderBy;

    /**
     * 排序方向 (ASC/DESC)
     */
    private String orderDirection = "ASC";

    /**
     * 获取偏移量
     */
    @JsonIgnore
    public Long getOffset() {
        return (current - 1) * size;
    }

    /**
     * 获取限制数量
     */
    @JsonIgnore
    public Long getLimit() {
        return size;
    }

    /**
     * 判断是否需要排序
     */
    @JsonIgnore
    public boolean hasOrderBy() {
        return orderBy != null && !orderBy.trim().isEmpty();
    }

    /**
     * 判断是否为升序
     */
    @JsonIgnore
    public boolean isAsc() {
        return "ASC".equalsIgnoreCase(orderDirection);
    }

    /**
     * 判断是否为降序
     */
    @JsonIgnore
    public boolean isDesc() {
        return "DESC".equalsIgnoreCase(orderDirection);
    }
}
